//
//  WSVideoDetail.m
//  CharonTVProject
//
//  Created by karong on 2023/8/8.
//

#import "WSVideoDetail.h"

@implementation WSVideoDetail

+ (NSDictionary *)mj_objectClassInArray {
    
    return @{@"chapter_list":NSClassFromString(@"WSVideo")};
}

///每一頁顯示的默認章節數量
- (NSInteger)onePageVideoCount {
    return 18;
}

///最後一頁顯示的章節數量
- (NSInteger)lastPageVideoCount {
    return self.total_chapter - (self.totalPage - 1) * self.onePageVideoCount;
}

///每一頁顯示的章節數量
- (NSInteger)videoCountWithPage:(NSInteger)page {
    NSInteger onePageVideoCount = self.onePageVideoCount;
    if (page == self.totalPage - 1) {
        onePageVideoCount = self.lastPageVideoCount;
    }
    return onePageVideoCount;
}

///每一頁開始的章節
- (NSInteger)startWithPage:(NSInteger)page {
    return page * self.onePageVideoCount;
}

///每一頁結束的章節
- (NSInteger)endWithPage:(NSInteger)page {
    return [self startWithPage:page] + [self videoCountWithPage:page];
}

- (NSInteger)totalPage {
    return ceil(self.total_chapter * 1.0f / self.onePageVideoCount);
}

///每一頁章節的區間
- (NSString *)pageTitle:(NSInteger)page {
    NSInteger start = [self startWithPage:page] + 1;
    NSInteger end = [self endWithPage:page];
    NSString * str = WSSF(@"%ld-%ld", (long)start, (long)end);
    return str;
}

///每一頁的章節
- (NSArray *)videoArrayWithPage:(NSInteger)page {
    NSArray *videoArray = [self.chapter_list subarrayWithRange:NSMakeRange([self startWithPage:page], [self videoCountWithPage:page])];
    return videoArray;
}
@end
